package com.yuncommunity.cloudlab.repository

import com.yuncommunity.cloudlab.model.User
import org.springframework.data.domain.Page
import org.springframework.data.domain.Pageable
import org.springframework.data.jpa.repository.JpaRepository
import org.springframework.data.jpa.repository.Modifying
import org.springframework.data.jpa.repository.Query
import org.springframework.transaction.annotation.Transactional
import java.util.*

interface UserRepository : JpaRepository<User, Long> {
    fun findByName(s: String): User?
    fun findByToken(s: String): User?
    fun findByNameAndPassword(name: String, md5DigestAsHex: String): User?
    fun findByPhone(phone: String): User?
    fun findByPhoneAndPassword(name: String, md5DigestAsHex: String): User?
    fun findAllByUserTypeContainsAndPhoneContainsAndIsDeleteFalse(pageable: Pageable, userType: String, phone: String): Page<User>
    fun existsByPhone(phone: String): Boolean

    @Modifying
    @Transactional
    @Query("update User u set u.isDelete=true where u.id in (:userList)")
    fun updateDelete(userList: ArrayList<Long>): Int
}